<UserControl x:Class="StockTraderRI.Modules.Position.PositionSummary.PositionSummaryView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
	xmlns:Infrastructure="clr-namespace:StockTraderRI.Infrastructure;assembly=StockTraderRI.Infrastructure" 
	xmlns:Commands="clr-namespace:Microsoft.Practices.Composite.Presentation.Commands;assembly=Microsoft.Practices.Composite.Presentation" 
	xmlns:Converters="clr-namespace:StockTraderRI.Infrastructure.Converters;assembly=StockTraderRI.Infrastructure"

    Width="Auto">
    <UserControl.Resources>
        <Converters:CurrencyConverter x:Key="currencyConverter" />
        <Converters:PercentConverter x:Key="percentConverter" />
        <Converters:DecimalToColorConverter x:Key="decimalToColorConverter" />
        <!-- The following resources are used as a workaround because in Silverlight we cannot bind to a RelativeSource -->
        <Infrastructure:ObservableCommand x:Key="BuyCommand" />
        <Infrastructure:ObservableCommand x:Key="SellCommand" />
    </UserControl.Resources>
    <data:DataGrid x:Name="PositionsGrid" AutomationProperties.AutomationId="PositionSummaryGrid"
		ItemsSource="{Binding Path=Position.Items}" 
		SelectedItem="{Binding Mode=TwoWay, Path=CurrentPositionSummaryItem}" 
		AutoGenerateColumns="False" BorderThickness="0,0,0,0" Background="{x:Null}" 
		BorderBrush="{x:Null}" HeadersVisibility="Column" GridLinesVisibility="None" 
		Foreground="#FF666666" Height="Auto" Style="{StaticResource CustomDataGridStyle}" 
		CellStyle="{StaticResource NoSelectionDataGridCellStyle}" 
		ColumnHeaderStyle="{StaticResource CustomHeaderStyle}" 
		SelectionMode="Single" IsReadOnly="True"
		DragIndicatorStyle="{StaticResource CustomHeaderStyle}" 
		RowStyle="{StaticResource CustomGridRowStyle}" HorizontalAlignment="Stretch" 
		Margin="0,0,0,0" MinColumnWidth="40" >
		<data:DataGrid.Columns>
			<data:DataGridTextColumn Header="Symbol" Binding="{Binding Path=TickerSymbol}"/>
			<data:DataGridTextColumn Header="Shares" Binding="{Binding Path=Shares}"/>
			<data:DataGridTextColumn Header="Current" Binding="{Binding Converter={StaticResource currencyConverter}, Path=CurrentPrice}"/>
			<data:DataGridTextColumn Header="Cost Basis" Binding="{Binding Converter={StaticResource currencyConverter}, Path=CostBasis}" />
			<data:DataGridTextColumn Header="Market Value" Binding="{Binding Converter={StaticResource currencyConverter}, Path=MarketValue}" />
            <data:DataGridTemplateColumn Header="Gain/Loss %">
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Converter={StaticResource percentConverter}, Path=GainLossPercent}" 
                                     Foreground="{Binding Converter={StaticResource decimalToColorConverter}, Path=GainLossPercent}" />
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>
            <data:DataGridTemplateColumn Header="Actions">
				<data:DataGridTemplateColumn.CellTemplate>
					<DataTemplate>
						<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
                            <Button Commands:Click.Command="{Binding Path=Value, Source={StaticResource BuyCommand}}" Commands:Click.CommandParameter="{Binding Path=TickerSymbol}" AutomationProperties.AutomationId="ActionsBuyButton" Template="{StaticResource AddButtonTemplate}" Cursor="Hand" />
                            <Button Commands:Click.Command="{Binding Path=Value, Source={StaticResource SellCommand}}" Commands:Click.CommandParameter="{Binding Path=TickerSymbol}" AutomationProperties.AutomationId="ActionsSellButton" Template="{StaticResource RemoveButtonTemplate}" Cursor="Hand" />
                        </StackPanel>
					</DataTemplate>
				</data:DataGridTemplateColumn.CellTemplate>
			</data:DataGridTemplateColumn>
		</data:DataGrid.Columns>
	</data:DataGrid>
</UserControl>
